define(['template','jquery'],(template) => {
    class Header{
        constructor () { 
            this.load().then(() => {
                this.getTabs().then((list)=> {
                    this.search_move()
                    this.tabsAc(list)
                })
            })
        }
        load () {
            return new Promise(resolve => {
                $('header').load('/html/modules/header.html',resolve)
            })
        }

        search_move () {
            this.search = $('#search')
            this.searchInput = $('#search_input')
            this.search.on('mouseenter',() => {
               
                this.search.stop("false", true).animate({
                    left:'164px'
                },900)
                $('#search_input').stop("false", true).animate({
                    "padding": "5px 50px 5px 20px",
                    "width": "130px"
                },600)
            })
            this.searchInput.on('mouseleave',() => {
                    
                    this.search.stop("false", true).animate({
                        left:'0px'
                    },600)
                    $('#search_input').stop("false", true).animate({
                        "padding": "5px 0px",
                        "width": "0px"
                    },900)
              
            })
        }

        getTabs () {
            return new Promise(resolve => {
                $.get('/libs/json/new.json',resp => {
                    
                    if (resp.code === 200) {
                         var list = resp.body.tabs
                        $('#tabs').html(template('tabsTemplate',{list}))
                        resolve(list)
                    }
                })
            })
        }

        tabsAc (list) {
            const idt = window.location.hash.slice(1)
            Array.from($('#tabs a')).forEach((item) => {
                if ($(item).attr('id') == idt) {
                    $(item).addClass('ac')
                }
            })
        }
    }
    return new Header()
});

